home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / bin / compiz < prev    next >
Encoding:
Text File  |  2009-05-01  |  11.9 KB  |  457 lines

  1. #!/bin/sh
  2. # Compiz Manager wrapper script
  3. # Copyright (c) 2007 Kristian Lyngst√∏l <kristian@bohemians.org>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  19. #
  20. #
  21. # Contributions by: Trevi√±o (3v1n0) <trevi55@gmail.com>, Ubuntu Packages
  22. #
  23. # Much of this code is based on Beryl code, also licensed under the GPL.
  24. # This script will detect what options we need to pass to compiz to get it
  25. # started, and start a default plugin and possibly window decorator.
  26.  
  27.  
  28. COMPIZ_BIN_PATH="/usr/local/bin/" # For window decorators and compiz
  29. PLUGIN_PATH="/usr/local/lib/compiz/" 
  30. GLXINFO="/usr/bin/glxinfo"
  31. KWIN="/usr/bin/kwin"
  32. METACITY="/usr/bin/metacity"
  33. XFWM="/usr/bin/xfwm"
  34. COMPIZ_NAME="compiz" # Final name for compiz (compiz.real) 
  35.  
  36. # For Xgl LD_PRELOAD
  37. LIBGL_NVIDIA="/usr/lib/nvidia/libGL.so.1.2.xlibmesa"
  38. LIBGL_FGLRX="/usr/lib/fglrx/libGL.so.1.2.xlibmesa"
  39.  
  40. # Minimum amount of memory (in kilo bytes) that nVidia cards need
  41. # to be allowed to start
  42. # Set to 262144 to require 256MB
  43. NVIDIA_MEMORY="65536" # 64MB
  44. NVIDIA_SETTINGS="nvidia-settings" # Assume it's in the path by default
  45.  
  46. # For detecting what driver is in use, the + is for one or more /'s
  47. XORG_DRIVER_PATH="/usr/lib/xorg/modules/drivers/+"
  48. FALLBACKWM="xterm"
  49. if [ x"$KDE_FULL_SESSION" = x"true" ]; then 
  50.         FALLBACKWM="${KWIN}";
  51. elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then 
  52.         FALLBACKWM="${METACITY}"
  53. elif xprop -root _DT_SAVE_MODE | grep ' = \"xfce4\"$' >/dev/null 2>&1; then 
  54.         FALLBACKWM="${XFWM}"
  55. fi
  56.  
  57. FALLBACKWM_OPTIONS="--replace $@"
  58.  
  59. # Driver whitelist
  60. WHITELIST="nvidia intel ati radeon i810 fglrx"
  61.  
  62. # blacklist based on the pci ids 
  63. # See http://wiki.compiz-fusion.org/Hardware/Blacklist for details
  64. #T="   1002:5954 1002:5854 1002:5955" # ati rs480
  65. #T="$T 1002:4153" # ATI Rv350
  66. #T="$T 8086:2982 8086:2992 8086:29a2 8086:2a02 8086:2a12"  # intel 965
  67. #T="$T 8086:2e02 " # Intel Eaglelake
  68. T="$T 8086:3577 8086:2562 " # Intel 830MG, 845G (LP: #259385)
  69. BLACKLIST_PCIIDS="$T"
  70. unset T
  71.  
  72. COMPIZ_OPTIONS="--ignore-desktop-hints --replace"
  73. COMPIZ_PLUGINS="core"
  74. ENV=""
  75.  
  76. # Use emerald by default if it exist
  77. USE_EMERALD="yes"
  78.  
  79. # No indirect by default
  80. INDIRECT="no"
  81.  
  82. # Default X.org log if xset q doesn't reveal it
  83. XORG_DEFAULT_LOG="/var/log/Xorg.0.log"
  84.  
  85. # Set to yes to enable verbose
  86. VERBOSE="yes"
  87.  
  88. # Echos the arguments if verbose
  89. verbose()
  90. {
  91.     if [ "x$VERBOSE" = "xyes" ]; then
  92.         printf "$*"
  93.     fi
  94. }
  95.  
  96. # abort script and run fallback windowmanager
  97. abort_with_fallback_wm()
  98. {
  99.     if [ "x$SKIP_CHECKS" = "xyes" ]; then
  100.         verbose "SKIP_CHECKS is yes, so continuing despite problems.\n"
  101.         return 0;
  102.     fi
  103.     
  104.     if [ "x$CM_DRY" = "xyes" ]; then
  105.         verbose "Dry run failed: Problems detected with 3D support.'n"
  106.         exit 1;
  107.     fi
  108.  
  109.     verbose "aborting and using fallback: $FALLBACKWM \n"
  110.  
  111.     if [ -x $FALLBACKWM ]; then
  112.         exec $FALLBACKWM $FALLBACKWM_OPTIONS
  113.     else
  114.         printf "no $FALLBACKWM found, exiting\n"
  115.         exit 1
  116.     fi
  117. }
  118.  
  119. # Check if we run with the Software Rasterizer, this happens e.g.
  120. # when a second screen session is opened via f-u-a on intel
  121. check_software_rasterizer()
  122. {
  123.     verbose "Checking for Software Rasterizer: "
  124.     if glxinfo 2> /dev/null | egrep -q '^OpenGL renderer string: Software Rasterizer' ; then
  125.         verbose "present. \n";
  126.         return 0;
  127.     else
  128.         verbose "Not present. \n"
  129.         return 1;
  130.     fi
  131.  
  132. }
  133.  
  134. # Check for non power of two texture support
  135. check_npot_texture()
  136. {
  137.     verbose "Checking for non power of two support: "
  138.     if glxinfo 2> /dev/null | egrep -q '(GL_ARB_texture_non_power_of_two|GL_NV_texture_rectangle|GL_EXT_texture_rectangle|GL_ARB_texture_rectangle)' ; then
  139.         verbose "present. \n";
  140.         return 0;
  141.     else
  142.         verbose "Not present. \n"
  143.         return 1;
  144.     fi
  145.  
  146. }
  147.  
  148. # Check for presence of FBConfig
  149. check_fbconfig()
  150. {
  151.     verbose "Checking for FBConfig: "
  152.     if [ "$INDIRECT" = "yes" ]; then
  153.         $GLXINFO -i | grep -q GLX.*fbconfig 
  154.         FB=$?
  155.     else
  156.         $GLXINFO | grep -q GLX.*fbconfig 
  157.         FB=$?
  158.     fi
  159.  
  160.     if [ $FB = "0" ]; then
  161.         unset FB
  162.         verbose "present. \n"
  163.         return 0;
  164.     else
  165.         unset FB
  166.         verbose "not present. \n"
  167.         return 1;
  168.     fi
  169. }
  170.  
  171.  
  172. # Check for TFP
  173. check_tfp()
  174. {
  175.     verbose "Checking for texture_from_pixmap: "
  176.     if [ $($GLXINFO 2>/dev/null | grep -c GLX_EXT_texture_from_pixmap) -gt 2 ] ; then
  177.         verbose "present. \n"
  178.         return 0;
  179.     else
  180.         verbose "not present. \n"
  181.         if [ "$INDIRECT" = "yes" ]; then
  182.             unset LIBGL_ALWAYS_INDIRECT
  183.             INDIRECT="no"
  184.             return 1;
  185.         else
  186.             verbose "Trying again with indirect rendering:\n";
  187.             INDIRECT="yes"
  188.             export LIBGL_ALWAYS_INDIRECT=1
  189.             check_tfp;
  190.             return $?
  191.         fi
  192.     fi
  193. }
  194.  
  195. # Check wether the composite extension is present
  196. check_composite()
  197. {
  198.     verbose "Checking for Composite extension: "
  199.     if xdpyinfo -queryExtensions | grep -q Composite ; then
  200.         verbose "present. \n";
  201.         return 0;
  202.     else
  203.         verbose "not present. \n";
  204.         return 1;
  205.     fi
  206. }
  207.  
  208. # Detects if Xgl is running
  209. check_xgl()
  210. {
  211.     verbose "Checking for Xgl: "
  212.     if xvinfo | grep -q Xgl ; then
  213.         verbose "present. \n"
  214.         return 0;
  215.     else
  216.         verbose "not present. \n"
  217.         return 1;
  218.     fi
  219. }
  220.  
  221. # Check if the nVidia card has enough video ram to make sense
  222. check_nvidia_memory()
  223. {
  224.     if [ ! -x "$NVIDIA_SETTINGS" ]; then
  225.     return 0
  226.     fi
  227.  
  228.     MEM=$(${NVIDIA_SETTINGS} -q VideoRam | egrep Attribute\ \'VideoRam\'\ .*: | cut -d: -f3 | sed 's/[^0-9]//g')
  229.     if [ $MEM -lt $NVIDIA_MEMORY ]; then
  230.         verbose "Less than ${NVIDIA_MEMORY}kb of memory and nVidia";
  231.         return 1;
  232.     fi
  233.     return 0;
  234. }
  235.  
  236. # Check for existence if NV-GLX
  237. check_nvidia()
  238. {
  239.     if [ ! -z $NVIDIA_INTERNAL_TEST ]; then
  240.         return $NVIDIA_INTERNAL_TEST;
  241.     fi
  242.     verbose "Checking for nVidia: "
  243.     if xdpyinfo | grep -q NV-GLX ; then
  244.         verbose "present. \n"
  245.         NVIDIA_INTERNAL_TEST=0
  246.         return 0;
  247.     else
  248.         verbose "not present. \n"
  249.         NVIDIA_INTERNAL_TEST=1
  250.         return 1;
  251.     fi
  252. }
  253.  
  254. # Check if the max texture size is large enough compared to the resolution
  255. check_texture_size()
  256. {
  257.     # Check how many screens we've got and iterate over them
  258.     N=$(xdpyinfo | grep -i "number of screens" | sed 's/.*[^0-9]//g')
  259.     for i in $(seq 1 $N); do
  260.         verbose "Checking screen $i"
  261.         TEXTURE_LIMIT=$(glxinfo -l | grep GL_MAX_TEXTURE_SIZE | sed -n "$i s/^.*=[^0-9]//g p")
  262.         RESOLUTION=$(xdpyinfo | grep -i dimensions: | sed -n -e "$i s/^ *dimensions: *\([0-9]*x[0-9]*\) pixels.*/\1/ p")
  263.         VRES=$(echo $RESOLUTION | sed 's/.*x//')
  264.         HRES=$(echo $RESOLUTION | sed 's/x.*//')
  265.         verbose "Comparing resolution ($RESOLUTION) to maximum 3D texture size ($TEXTURE_LIMIT): ";
  266.         if [ $VRES -gt $TEXTURE_LIMIT ] || [ $HRES -gt $TEXTURE_LIMIT ]; then
  267.         verbose "Failed.\n"
  268.         return 1;
  269.         fi
  270.         verbose "Passed.\n"
  271.     done
  272.     return 0
  273. }
  274.  
  275. # check driver whitelist
  276. running_under_whitelisted_driver()
  277. {
  278.     LOG=$(xset q|grep "Log file"|awk '{print $3}')
  279.     if [ "$LOG" = "" ]; then
  280.         verbose "xset q doesn't reveal the location of the log file. Using fallback $XORG_DEFAULT_LOG \n"
  281.         LOG=$XORG_DEFAULT_LOG;
  282.     fi
  283.     if [ -z "$LOG" ];then
  284.         verbose "AIEEEEH, no Log file found \n"
  285.         verbose "$(xset q) \n"
  286.     return 0
  287.     fi
  288.     for DRV in ${WHITELIST}; do
  289.         if egrep -q "Loading ${XORG_DRIVER_PATH}${DRV}_drv\.so" $LOG &&
  290.            ! egrep -q "Unloading ${XORG_DRIVER_PATH}${DRV}_drv\.so" $LOG; 
  291.         then
  292.             return 0
  293.         fi
  294.     done
  295.     verbose "No whitelisted driver found\n"
  296.     return 1
  297. }
  298.  
  299. # check pciid blacklist
  300. have_blacklisted_pciid()
  301. {
  302.     OUTPUT=$(lspci -n)
  303.     for ID in ${BLACKLIST_PCIIDS}; do
  304.         if echo "$OUTPUT" | egrep -q "$ID"; then
  305.             verbose "Blacklisted PCIID '$ID' found \n"
  306.             return 0
  307.         fi
  308.     done
  309.     OUTPUT=$(lspci -vn | grep -i VGA)
  310.     verbose "Detected PCI ID for VGA: $OUTPUT\n"
  311.     return 1
  312. }
  313.  
  314. build_env()
  315. {
  316.     if check_nvidia; then
  317.         ENV="__GL_YIELD=NOTHING "
  318.     fi
  319.     if [ "$INDIRECT" = "yes" ]; then
  320.         ENV="$ENV LIBGL_ALWAYS_INDIRECT=1 "
  321.     fi
  322.     if check_xgl; then
  323.         if [ -f ${LIBGL_NVIDIA} ]; then
  324.             ENV="$ENV LD_PRELOAD=${LIBGL_NVIDIA}"
  325.             verbose "Enabling Xgl with nVidia drivers...\n"
  326.         fi
  327.         if [ -f ${LIBGL_FGLRX} ]; then
  328.             ENV="$ENV LD_PRELOAD=${LIBGL_FGLRX}"
  329.             verbose "Enabling Xgl with fglrx ATi drivers...\n"
  330.         fi
  331.     fi
  332.  
  333.     ENV="$ENV FROM_WRAPPER=yes"
  334.  
  335.     if [ -n "$ENV" ]; then
  336.         export $ENV
  337.     fi
  338. }
  339.  
  340. build_args()
  341. {
  342.     if [ "x$INDIRECT" = "xyes" ]; then
  343.         COMPIZ_OPTIONS="$COMPIZ_OPTIONS --indirect-rendering "
  344.     fi
  345.     if [ ! -z "$DESKTOP_AUTOSTART_ID" ]; then
  346.         COMPIZ_OPTIONS="$COMPIZ_OPTIONS --sm-client-id $DESKTOP_AUTOSTART_ID"
  347.     fi
  348.     if check_nvidia; then
  349.         if [ "x$INDIRECT" != "xyes" ]; then
  350.             COMPIZ_OPTIONS="$COMPIZ_OPTIONS --loose-binding"
  351.         fi
  352.     fi
  353. }
  354.  
  355. ####################
  356. # Execution begins here.
  357.  
  358. # Read configuration from XDG paths
  359. if [ -z "$XDG_CONFIG_DIRS" ]; then
  360.     test -f /etc/xdg/compiz/compiz-manager && . /etc/xdg/compiz/compiz-manager
  361.     for f in /etc/xdg/compiz/compiz-manager.d/*; do
  362.         test -e $f && . $f
  363.     done
  364. else
  365.         OLD_IFS=$IFS
  366.         IFS=:
  367.         for CONFIG_DIR in $XDG_CONFIG_DIRS
  368.         do
  369.                 test -f $CONFIG_DIR/compiz/compiz-manager && . $CONFIG_DIR/compiz/compiz-manager
  370.         for f in $CONFIG_DIRS/compiz/compiz-manager.d/*; do
  371.                     test -e $f && . $f
  372.         done
  373.         done
  374.         IFS=$OLD_IFS
  375.         unset OLD_IFS
  376. fi
  377.  
  378. if [ -z "$XDG_CONFIG_HOME" ]; then
  379.     test -f $HOME/.config/compiz/compiz-manager && . $HOME/.config/compiz/compiz-manager
  380. else
  381.     test -f $XDG_CONFIG_HOME/compiz/compiz-manager && .  $XDG_CONFIG_HOME/compiz/compiz-manager
  382. fi
  383.  
  384. # Don't use compiz when running the failsafe session
  385. if [ "x$GNOME_DESKTOP_SESSION_ID" = "xFailsafe" ]; then
  386.     abort_with_fallback_wm
  387. fi
  388.  
  389. if [ "x$LIBGL_ALWAYS_INDIRECT" = "x1" ]; then
  390.     INDIRECT="yes";
  391. fi
  392.  
  393. # if we run under Xgl, we can skip some tests here
  394. if ! check_xgl; then
  395.     # if vesa or vga are in use, do not even try glxinfo (LP#119341)
  396.     if ! running_under_whitelisted_driver || have_blacklisted_pciid; then
  397.         abort_with_fallback_wm
  398.     fi
  399.     # check if we have the required bits to run compiz and if not, 
  400.     # fallback
  401.     if ! check_tfp || ! check_npot_texture || ! check_composite || ! check_texture_size; then
  402.         abort_with_fallback_wm
  403.     fi
  404.  
  405.     # check if we run with software rasterizer and if so, bail out
  406.     if check_software_rasterizer; then
  407.         verbose "Software rasterizer detected, aborting"
  408.         abort_with_fallback_wm
  409.     fi
  410.  
  411.     if check_nvidia && ! check_nvidia_memory; then
  412.         abort_with_fallback_wm
  413.     fi
  414.  
  415.     if ! check_fbconfig; then
  416.         abort_with_fallback_wm
  417.     fi
  418. fi
  419.  
  420. # load the ccp plugin if present and fallback to plain gconf if not
  421. if [ -f ${PLUGIN_PATH}libccp.so ]; then
  422.     COMPIZ_PLUGINS="$COMPIZ_PLUGINS ccp"
  423. elif [ -f ${PLUGIN_PATH}libgconf.so ]; then
  424.     COMPIZ_PLUGINS="$COMPIZ_PLUGINS glib gconf"
  425. fi
  426.  
  427. # enable gnomecompat if we run under gnome
  428. if [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ] && [ ! -e ~/.compiz-gnomecompat ]; then 
  429.         verbose "running under gnome seesion, checking for gnomecompat\n"
  430.     if ! gconftool -g /apps/compiz/general/allscreens/options/active_plugins|grep -q gnomecompat; then
  431.         verbose "adding missing gnomecompat\n"
  432.         V=$(gconftool -g /apps/compiz/general/allscreens/options/active_plugins|sed s/mousepoll,/mousepoll,gnomecompat,/)
  433.            if ! echo $V|grep -q gnomecompat; then
  434.                verbose "can not add gnomecompat, reseting\n"
  435.                gconftool --unset /apps/compiz/general/allscreens/options/active_plugins
  436.            else
  437.             gconftool -s /apps/compiz/general/allscreens/options/active_plugins --type list --list-type=string $V
  438.            fi
  439.            touch ~/.compiz-gnomecompat
  440.     fi
  441. fi
  442.  
  443. # get environment
  444. build_env
  445. build_args
  446.  
  447. if [ "x$CM_DRY" = "xyes" ]; then
  448.     verbose "Dry run finished: everything should work with regards to Compiz and 3D.\n"
  449.     verbose "Execute: ${COMPIZ_BIN_PATH}${COMPIZ_NAME} $COMPIZ_OPTIONS "$@" $COMPIZ_PLUGINS \n"
  450.     exit 0;
  451. fi
  452.  
  453. ${COMPIZ_BIN_PATH}${COMPIZ_NAME} $COMPIZ_OPTIONS "$@" $COMPIZ_PLUGINS || exec $FALLBACKWM $FALLBACKWM_OPTIONS
  454.  
  455.